home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_014 / dex / dex.c next >
C/C++ Source or Header  |  1992-05-06  |  15KB  |  642 lines

  1.  
  2. # line 2 "dex.y"
  3. /************************************************************************
  4.  *                                    *
  5.  *            Copyright (c) 1982, Fred Fish            *
  6.  *                All Rights Reserved                *
  7.  *                                    *
  8.  *    This software and/or documentation is released for public    *
  9.  *    distribution for personal, non-commercial use only.        *
  10.  *    Limited rights to use, modify, and redistribute are hereby    *
  11.  *    granted for non-commercial purposes, provided that all        *
  12.  *    copyright notices remain intact and all changes are clearly    *
  13.  *    documented.  The author makes no warranty of any kind with    *
  14.  *    respect to this product and explicitly disclaims any implied    *
  15.  *    warranties of merchantability or fitness for any particular    *
  16.  *    purpose.                            *
  17.  *                                    *
  18.  ************************************************************************
  19.  */
  20.  
  21. # line 61 "dex.y"
  22. #include <stdio.h>
  23.  
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27. char savedtext[256];        /* Text for current line */
  28.  
  29. extern char *infile;        /* Input file name if not stdin */
  30. extern int linenum;        /* Current input file line number */
  31. extern FILE *infp;        /* Input stream */
  32. extern int debug;        /* Debug variable */
  33.  
  34. # define BSTART 257
  35. # define TEXT 258
  36. # define JUNK 259
  37. # define HSTART 260
  38. # define FSTART 261
  39. # define UFSTART 262
  40. # define NEWLINE 263
  41. #define yyclearin yychar = -1
  42. #define yyerrok yyerrflag = 0
  43. extern int yychar;
  44. extern int yyerrflag;
  45. #ifndef YYMAXDEPTH
  46. #define YYMAXDEPTH 150
  47. #endif
  48. #ifndef YYSTYPE
  49. #define YYSTYPE int
  50. #endif
  51. YYSTYPE yylval, yyval;
  52. typedef int yytabelem;
  53. # define YYERRCODE 256
  54.  
  55. # line 154 "dex.y"
  56.  
  57.  
  58. #include "dex.lo"        /* LEX output; renamed from lex.yy.c */
  59.  
  60. yywrap ()            /* Thought this was in library */
  61. {
  62.     return(1);
  63. }
  64.  
  65. yyerror(sp)
  66. char *sp;
  67. {
  68.     fprintf(stderr,"%s: ",infile);        /* What file */
  69.     fprintf(stderr,"line %d: ",linenum);    /* Where in file */
  70.     fprintf(stderr,"%s: ",sp);            /* What was wrong */
  71.     fprintf(stderr,"%s\n",yytext);        /* What it choked on */
  72. }
  73.  
  74. yytabelem yyexca[] ={
  75. -1, 1,
  76.     0, -1,
  77.     -2, 0,
  78.     };
  79. # define YYNPROD 18
  80. # define YYLAST 31
  81. yytabelem yyact[]={
  82.  
  83.     11,    14,     8,    10,    12,    13,    14,    18,     9,    17,
  84.      7,     2,    16,    15,     6,     5,     4,     3,     1,     0,
  85.     19,     0,    20,    21,     0,     0,    22,     0,     0,    23,
  86.     24 };
  87. yytabelem yypact[]={
  88.  
  89.   -257,  -257, -1000,  -262, -1000, -1000, -1000, -1000, -1000, -1000,
  90.   -251,  -262,  -251,  -251, -1000, -1000, -1000,  -262, -1000, -1000,
  91.   -262,  -262, -1000, -1000, -1000 };
  92. yytabelem yypgo[]={
  93.  
  94.      0,    18,    11,    17,    16,    15,    14,    10,     8,     9 };
  95. yytabelem yyr1[]={
  96.  
  97.      0,     1,     1,     1,     2,     2,     2,     2,     2,     3,
  98.      3,     3,     4,     5,     6,     7,     8,     9 };
  99. yytabelem yyr2[]={
  100.  
  101.      0,     3,     5,     1,     3,     3,     3,     3,     3,     3,
  102.      3,     5,     7,     5,     7,     7,     3,     3 };
  103. yytabelem yychk[]={
  104.  
  105.  -1000,    -1,    -2,    -3,    -4,    -5,    -6,    -7,   259,    -8,
  106.    260,   257,   261,   262,   263,    -2,    -8,    -9,   258,    -8,
  107.     -9,    -9,    -8,    -8,    -8 };
  108. yytabelem yydef[]={
  109.  
  110.      3,    -2,     1,     4,     5,     6,     7,     8,     9,    10,
  111.      0,     0,     0,     0,    16,     2,    11,     0,    17,    13,
  112.      0,     0,    12,    14,    15 };
  113. typedef struct { char *t_name; int t_val; } yytoktype;
  114. #ifndef YYDEBUG
  115. #    define YYDEBUG    0    /* don't allow debugging */
  116. #endif
  117.  
  118. #if YYDEBUG
  119.  
  120. yytoktype yytoks[] =
  121. {
  122.     "BSTART",    257,
  123.     "TEXT",    258,
  124.     "JUNK",    259,
  125.     "HSTART",    260,
  126.     "FSTART",    261,
  127.     "UFSTART",    262,
  128.     "NEWLINE",    263,
  129.     "-unknown-",    -1    /* ends search */
  130. };
  131.  
  132. char * yyreds[] =
  133. {
  134.     "-no such reduction-",
  135.     "file : line",
  136.     "file : file line",
  137.     "file : /* empty */",
  138.     "line : junk",
  139.     "line : id_line",
  140.     "line : blank_line",
  141.     "line : filled_line",
  142.     "line : unfilled_line",
  143.     "junk : JUNK",
  144.     "junk : newline",
  145.     "junk : junk newline",
  146.     "id_line : HSTART text newline",
  147.     "blank_line : BSTART newline",
  148.     "filled_line : FSTART text newline",
  149.     "unfilled_line : UFSTART text newline",
  150.     "newline : NEWLINE",
  151.     "text : TEXT",
  152. };
  153. #endif /* YYDEBUG */
  154. /*    @(#)yaccpar    1.9    */
  155.  
  156. /*
  157. ** Skeleton parser driver for yacc output
  158. */
  159.  
  160. /*
  161. ** yacc user known macros and defines
  162. */
  163. #define YYERROR        goto yyerrlab
  164. #define YYACCEPT    return(0)
  165. #define YYABORT        return(1)
  166. #define YYBACKUP( newtoken, newvalue )\
  167. {\
  168.     if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
  169.     {\
  170.         yyerror( "syntax error - cannot backup" );\
  171.         goto yyerrlab;\
  172.     }\
  173.     yychar = newtoken;\
  174.     yystate = *yyps;\
  175.     yylval = newvalue;\
  176.     goto yynewstate;\
  177. }
  178. #define YYRECOVERING()    (!!yyerrflag)
  179. #ifndef YYDEBUG
  180. #    define YYDEBUG    1    /* make debugging available */
  181. #endif
  182.  
  183. /*
  184. ** user known globals
  185. */
  186. int yydebug;            /* set to 1 to get debugging */
  187.  
  188. /*
  189. ** driver internal defines
  190. */
  191. #define YYFLAG        (-1000)
  192.  
  193. /*
  194. ** global variables used by the parser
  195. */
  196. YYSTYPE yyv[ YYMAXDEPTH ];    /* value stack */
  197. int yys[ YYMAXDEPTH ];        /* state stack */
  198.  
  199. YYSTYPE *yypv;            /* top of value stack */
  200. int *yyps;            /* top of state stack */
  201.  
  202. int yystate;            /* current state */
  203. int yytmp;            /* extra var (lasts between blocks) */
  204.  
  205. int yynerrs;            /* number of errors */
  206. int yyerrflag;            /* error recovery flag */
  207. int yychar;            /* current input token number */
  208.  
  209.  
  210.  
  211. /*
  212. ** yyparse - return 0 if worked, 1 if syntax error not recovered from
  213. */
  214. int
  215. yyparse()
  216. {
  217.     register YYSTYPE *yypvt;    /* top of value stack for $vars */
  218.  
  219.     /*
  220.     ** Initialize externals - yyparse may be called more than once
  221.     */
  222.     yypv = &yyv[-1];
  223.     yyps = &yys[-1];
  224.     yystate = 0;
  225.     yytmp = 0;
  226.     yynerrs = 0;
  227.     yyerrflag = 0;
  228.     yychar = -1;
  229.  
  230.     goto yystack;
  231.     {
  232.         register YYSTYPE *yy_pv;    /* top of value stack */
  233.         register int *yy_ps;        /* top of state stack */
  234.         register int yy_state;        /* current state */
  235.         register int  yy_n;        /* internal state number info */
  236.  
  237.         /*
  238.         ** get globals into registers.
  239.         ** branch to here only if YYBACKUP was called.
  240.         */
  241.     yynewstate:
  242.         yy_pv = yypv;
  243.         yy_ps = yyps;
  244.         yy_state = yystate;
  245.         goto yy_newstate;
  246.  
  247.         /*
  248.         ** get globals into registers.
  249.         ** either we just started, or we just finished a reduction
  250.         */
  251.     yystack:
  252.         yy_pv = yypv;
  253.         yy_ps = yyps;
  254.         yy_state = yystate;
  255.  
  256.         /*
  257.         ** top of for (;;) loop while no reductions done
  258.         */
  259.     yy_stack:
  260.         /*
  261.         ** put a state and value onto the stacks
  262.         */
  263. #if YYDEBUG
  264.         /*
  265.         ** if debugging, look up token value in list of value vs.
  266.         ** name pairs.  0 and negative (-1) are special values.
  267.         ** Note: linear search is used since time is not a real
  268.         ** consideration while debugging.
  269.         */
  270.         if ( yydebug )
  271.         {
  272.             register int yy_i;
  273.  
  274.             printf( "State %d, token ", yy_state );
  275.             if ( yychar == 0 )
  276.                 printf( "end-of-file\n" );
  277.             else if ( yychar < 0 )
  278.                 printf( "-none-\n" );
  279.             else
  280.             {
  281.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  282.                     yy_i++ )
  283.                 {
  284.                     if ( yytoks[yy_i].t_val == yychar )
  285.                         break;
  286.                 }
  287.                 printf( "%s\n", yytoks[yy_i].t_name );
  288.             }
  289.         }
  290. #endif /* YYDEBUG */
  291.         if ( ++yy_ps >= &yys[ YYMAXDEPTH ] )    /* room on stack? */
  292.         {
  293.             yyerror( "yacc stack overflow" );
  294.             YYABORT;
  295.         }
  296.         *yy_ps = yy_state;
  297.         *++yy_pv = yyval;
  298.  
  299.         /*
  300.         ** we have a new state - find out what to do
  301.         */
  302.     yy_newstate:
  303.         if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
  304.             goto yydefault;        /* simple state */
  305. #if YYDEBUG
  306.         /*
  307.         ** if debugging, need to mark whether new token grabbed
  308.         */
  309.         yytmp = yychar < 0;
  310. #endif
  311.         if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  312.             yychar = 0;        /* reached EOF */
  313. #if YYDEBUG
  314.         if ( yydebug && yytmp )
  315.         {
  316.             register int yy_i;
  317.  
  318.             printf( "Received token " );
  319.             if ( yychar == 0 )
  320.                 printf( "end-of-file\n" );
  321.             else if ( yychar < 0 )
  322.                 printf( "-none-\n" );
  323.             else
  324.             {
  325.                 for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
  326.                     yy_i++ )
  327.                 {
  328.                     if ( yytoks[yy_i].t_val == yychar )
  329.                         break;
  330.                 }
  331.                 printf( "%s\n", yytoks[yy_i].t_name );
  332.             }
  333.         }
  334. #endif /* YYDEBUG */
  335.         if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
  336.             goto yydefault;
  337.         if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )    /*valid shift*/
  338.         {
  339.             yychar = -1;
  340.             yyval = yylval;
  341.             yy_state = yy_n;
  342.             if ( yyerrflag > 0 )
  343.                 yyerrflag--;
  344.             goto yy_stack;
  345.         }
  346.  
  347.     yydefault:
  348.         if ( ( yy_n = yydef[ yy_state ] ) == -2 )
  349.         {
  350. #if YYDEBUG
  351.             yytmp = yychar < 0;
  352. #endif
  353.             if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
  354.                 yychar = 0;        /* reached EOF */
  355. #if YYDEBUG
  356.             if ( yydebug && yytmp )
  357.             {
  358.                 register int yy_i;
  359.  
  360.                 printf( "Received token " );
  361.                 if ( yychar == 0 )
  362.                     printf( "end-of-file\n" );
  363.                 else if ( yychar < 0 )
  364.                     printf( "-none-\n" );
  365.                 else
  366.                 {
  367.                     for ( yy_i = 0;
  368.                         yytoks[yy_i].t_val >= 0;
  369.                         yy_i++ )
  370.                     {
  371.                         if ( yytoks[yy_i].t_val
  372.                             == yychar )
  373.                         {
  374.                             break;
  375.                         }
  376.                     }
  377.                     printf( "%s\n", yytoks[yy_i].t_name );
  378.                 }
  379.             }
  380. #endif /* YYDEBUG */
  381.             /*
  382.             ** look through exception table
  383.             */
  384.             {
  385.                 register int *yyxi = yyexca;
  386.  
  387.                 while ( ( *yyxi != -1 ) ||
  388.                     ( yyxi[1] != yy_state ) )
  389.                 {
  390.                     yyxi += 2;
  391.                 }
  392.                 while ( ( *(yyxi += 2) >= 0 ) &&
  393.                     ( *yyxi != yychar ) )
  394.                     ;
  395.                 if ( ( yy_n = yyxi[1] ) < 0 )
  396.                     YYACCEPT;
  397.             }
  398.         }
  399.  
  400.         /*
  401.         ** check for syntax error
  402.         */
  403.         if ( yy_n == 0 )    /* have an error */
  404.         {
  405.             /* no worry about speed here! */
  406.             switch ( yyerrflag )
  407.             {
  408.             case 0:        /* new error */
  409.                 yyerror( "syntax error" );
  410.                 goto skip_init;
  411.             yyerrlab:
  412.                 /*
  413.                 ** get globals into registers.
  414.                 ** we have a user generated syntax type error
  415.                 */
  416.                 yy_pv = yypv;
  417.                 yy_ps = yyps;
  418.                 yy_state = yystate;
  419.                 yynerrs++;
  420.             skip_init:
  421.             case 1:
  422.             case 2:        /* incompletely recovered error */
  423.                     /* try again... */
  424.                 yyerrflag = 3;
  425.                 /*
  426.                 ** find state where "error" is a legal
  427.                 ** shift action
  428.                 */
  429.                 while ( yy_ps >= yys )
  430.                 {
  431.                     yy_n = yypact[ *yy_ps ] + YYERRCODE;
  432.                     if ( yy_n >= 0 && yy_n < YYLAST &&
  433.                         yychk[yyact[yy_n]] == YYERRCODE)                    {
  434.                         /*
  435.                         ** simulate shift of "error"
  436.                         */
  437.                         yy_state = yyact[ yy_n ];
  438.                         goto yy_stack;
  439.                     }
  440.                     /*
  441.                     ** current state has no shift on
  442.                     ** "error", pop stack
  443.                     */
  444. #if YYDEBUG
  445. #    define _POP_ "Error recovery pops state %d, uncovers state %d\n"
  446.                     if ( yydebug )
  447.                         printf( _POP_, *yy_ps,
  448.                             yy_ps[-1] );
  449. #    undef _POP_
  450. #endif
  451.                     yy_ps--;
  452.                     yy_pv--;
  453.                 }
  454.                 /*
  455.                 ** there is no state on stack with "error" as
  456.                 ** a valid shift.  give up.
  457.                 */
  458.                 YYABORT;
  459.             case 3:        /* no shift yet; eat a token */
  460. #if YYDEBUG
  461.                 /*
  462.                 ** if debugging, look up token in list of
  463.                 ** pairs.  0 and negative shouldn't occur,
  464.                 ** but since timing doesn't matter when
  465.                 ** debugging, it doesn't hurt to leave the
  466.                 ** tests here.
  467.                 */
  468.                 if ( yydebug )
  469.                 {
  470.                     register int yy_i;
  471.  
  472.                     printf( "Error recovery discards " );
  473.                     if ( yychar == 0 )
  474.                         printf( "token end-of-file\n" );
  475.                     else if ( yychar < 0 )
  476.                         printf( "token -none-\n" );
  477.                     else
  478.                     {
  479.                         for ( yy_i = 0;
  480.                             yytoks[yy_i].t_val >= 0;
  481.                             yy_i++ )
  482.                         {
  483.                             if ( yytoks[yy_i].t_val
  484.                                 == yychar )
  485.                             {
  486.                                 break;
  487.                             }
  488.                         }
  489.                         printf( "token %s\n",
  490.                             yytoks[yy_i].t_name );
  491.                     }
  492.                 }
  493. #endif /* YYDEBUG */
  494.                 if ( yychar == 0 )    /* reached EOF. quit */
  495.                     YYABORT;
  496.                 yychar = -1;
  497.                 goto yy_newstate;
  498.             }
  499.         }/* end if ( yy_n == 0 ) */
  500.         /*
  501.         ** reduction by production yy_n
  502.         ** put stack tops, etc. so things right after switch
  503.         */
  504. #if YYDEBUG
  505.         /*
  506.         ** if debugging, print the string that is the user's
  507.         ** specification of the reduction which is just about
  508.         ** to be done.
  509.         */
  510.         if ( yydebug )
  511.             printf( "Reduce by (%d) \"%s\"\n",
  512.                 yy_n, yyreds[ yy_n ] );
  513. #endif
  514.         yytmp = yy_n;            /* value to switch over */
  515.         yypvt = yy_pv;            /* $vars top of value stack */
  516.         /*
  517.         ** Look in goto table for next state
  518.         ** Sorry about using yy_state here as temporary
  519.         ** register variable, but why not, if it works...
  520.         ** If yyr2[ yy_n ] doesn't have the low order bit
  521.         ** set, then there is no action to be done for
  522.         ** this reduction.  So, no saving & unsaving of
  523.         ** registers done.  The only difference between the
  524.         ** code just after the if and the body of the if is
  525.         ** the goto yy_stack in the body.  This way the test
  526.         ** can be made before the choice of what to do is needed.
  527.         */
  528.         {
  529.             /* length of production doubled with extra bit */
  530.             register int yy_len = yyr2[ yy_n ];
  531.  
  532.             if ( !( yy_len & 01 ) )
  533.             {
  534.                 yy_len >>= 1;
  535.                 yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  536.                 yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  537.                     *( yy_ps -= yy_len ) + 1;
  538.                 if ( yy_state >= YYLAST ||
  539.                     yychk[ yy_state =
  540.                     yyact[ yy_state ] ] != -yy_n )
  541.                 {
  542.                     yy_state = yyact[ yypgo[ yy_n ] ];
  543.                 }
  544.                 goto yy_stack;
  545.             }
  546.             yy_len >>= 1;
  547.             yyval = ( yy_pv -= yy_len )[1];    /* $$ = $1 */
  548.             yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
  549.                 *( yy_ps -= yy_len ) + 1;
  550.             if ( yy_state >= YYLAST ||
  551.                 yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
  552.             {
  553.                 yy_state = yyact[ yypgo[ yy_n ] ];
  554.             }
  555.         }
  556.                     /* save until reenter driver code */
  557.         yystate = yy_state;
  558.         yyps = yy_ps;
  559.         yypv = yy_pv;
  560.     }
  561.     /*
  562.     ** code supplied by user is placed in this switch
  563.     */
  564.     switch( yytmp )
  565.     {
  566.         
  567. case 1:
  568. # line 80 "dex.y"
  569. {if(debug){printf("yyparse: file\n");}} break;
  570. case 2:
  571. # line 82 "dex.y"
  572. {if(debug){printf("yyparse: file\n");}} break;
  573. case 3:
  574. # line 84 "dex.y"
  575. {if(debug){printf("yyparse: file\n");}} break;
  576. case 4:
  577. # line 88 "dex.y"
  578. {
  579.                 if(debug){printf("yyparse: line\n");}
  580.                 reset_section();
  581.             } break;
  582. case 5:
  583. # line 93 "dex.y"
  584. {if(debug){printf("yyparse: line\n");}} break;
  585. case 6:
  586. # line 95 "dex.y"
  587. {if(debug){printf("yyparse: line\n");}} break;
  588. case 7:
  589. # line 97 "dex.y"
  590. {if(debug){printf("yyparse: line\n");}} break;
  591. case 8:
  592. # line 99 "dex.y"
  593. {if(debug){printf("yyparse: line\n");}} break;
  594. case 9:
  595. # line 103 "dex.y"
  596. {if(debug){printf("yyparse: junk\n");}} break;
  597. case 10:
  598. # line 105 "dex.y"
  599. {if(debug){printf("yyparse: junk\n");}} break;
  600. case 11:
  601. # line 107 "dex.y"
  602. {if(debug){printf("yyparse: junk\n");}} break;
  603. case 12:
  604. # line 111 "dex.y"
  605. {
  606.                 {if(debug){printf("yyparse: id_line\n");}}
  607.                 set_section(savedtext);
  608.             } break;
  609. case 13:
  610. # line 119 "dex.y"
  611. {
  612.                 {if(debug){printf("yyparse: blank_line\n");}}
  613.                 emit_bline();
  614.             } break;
  615. case 14:
  616. # line 126 "dex.y"
  617. {
  618.                 {if(debug){printf("yyparse: filled_line\n");}}
  619.                 emit_filled(savedtext);
  620.             } break;
  621. case 15:
  622. # line 133 "dex.y"
  623. {
  624.                 {if(debug){printf("yyparse: unfilled_line\n");}}
  625.                 emit_unfilled(savedtext);
  626.             } break;
  627. case 16:
  628. # line 141 "dex.y"
  629. {
  630.                 {if(debug){printf("yyparse: newline\n");}}
  631.                 linenum++;
  632.             } break;
  633. case 17:
  634. # line 148 "dex.y"
  635. {
  636.                 {if(debug){printf("yyparse: text\n");}}
  637.                 strcpy(savedtext,yytext);
  638.             } break;
  639.     }
  640.     goto yystack;        /* reset registers in driver code */
  641. }
  642.